package com.lg.startertemplate.controller;

import com.lg.startertemplate.dao.impl.TargetDao;
import com.lg.startertemplate.domain.Target;
import com.lg.startertemplate.domain.TargetKey;
import com.lg.startertemplate.jpaenum.Country;
import com.lg.startertemplate.utiles.TimeUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Optional;

@Api(tags = "联合主键")
@RestController
public class TargetController {

    @Autowired
    private TargetDao targetDao;

    @GetMapping("createTarget")
    public void createTarget() {
        Target target = new Target("aa", new Date(), Country.CHINA,"描述");
        targetDao.save(target);

    }

    @GetMapping("testDoubleKey")
    public Target testDoubleKey(String time) {
        Date date = new Date(TimeUtils.strFormatLong(time));
        Optional<Target> aa = targetDao.findById(new TargetKey("aa", date));
        return aa.get();
    }
}
